﻿using System.Collections.Generic;
using System.Linq;
using Microsoft.Practices.ServiceLocation;
using NBlock.Core;
using Cost.Models;

namespace Cost.Services
{
    public class nbPrivilegeService : IPrivilegeService
    {
        public IList<IPrivilege> GetMenuPrivileges()
        {
            string type = PrivilegeType.Menu.ToString();
            var repo = ServiceLocator.Current.GetInstance<ICostRepository<Privilege>>();
            var list = repo.FindAll(p => p.PrivilegeType == type)
                .OrderBy(p => p.SeqNo)
                .Select(p => new nbPrivilege
                {
                    Id = p.Id,
                    Code = p.PrivilegeCode,
                    Name = p.PrivilegeName,
                    ParentId = p.ParentId,
                    ParentCode = p.ParentCode,
                    Url = p.Url,
                }).ToList();

            return list.Select(p => p as IPrivilege).ToList();
        }
    }
}
